<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateChatServiceLogTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('chat_service_log', ['comment' => 'chat服务记录', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('chat_user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => 'chat user'])
            ->addColumn('customer_service_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '客服'])
            ->addColumn('room_id', 'string', ['limit' => 60, 'default' => 'admin', 'comment' => '房间号'])
            ->addColumn('starttime', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '开始时间'])
            ->addColumn('endtime', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '结束时间'])
            ->addColumn(Column::enum('status', ['waiting', 'ing', 'end'])->setDefault('waiting')->setComment('状态'))
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('chat_user_id')
            ->addIndex('customer_service_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('chat_service_log');
        $table->drop();
    }
}
